<template>
	<view>
		<web-view :webview-styles="webviewStyles" :src="webUrl" v-if="webUrl"></web-view>
	</view>
</template>

<script>
	var currentWebview
	export default {
		data() {
			return {
				webUrl:"",
				webviewStyles: {
					progress: {
						color: this.$mainColor
					}
				}
			}
		},
		onLoad() {
			this.$nextTick(()=>{
				var _this = this
				uni.getStorage({
					key:"webData",
					success(event){
						if(event.data) {
							var data = null
							try{
								data = JSON.parse(event.data)
							}catch(e){
								//TODO handle the exception
							}
							//如果有要求设置cookie则跳转页面
							if(data['setCookie']) {
								//_this._setCookie(data['url'],uni.core.bsessionid)
							}else{
								_this.webUrl = data['url']
								_this.$forceUpdate()
								_this._setCalable()
							}
							uni.setNavigationBarTitle({
								title:data['title']
							})
						}
						uni.removeStorage({
							key:"webData"
						})
					}
				})
			})
		},
		methods: {
			//设置可双指缩放
			_setCalable(){
				// #ifdef APP-PLUS
				currentWebview = this.$mp.page.$getAppWebview()
				setTimeout(()=> {
				    currentWebview = currentWebview.children()[0]
				    currentWebview.setStyle({scalable:true})
				}, 500); //如果是页面初始化调用时，需要延时一下
				// #endif
			},
			_setCookie(pageUrl,bid){
				var _url = "/hybrid/html/setCookie.html?page={0}&bid={1}"
				this.webUrl = uni.core.strFormat(_url,encodeURIComponent(pageUrl),bid)
				this.$forceUpdate()
				this._setCalable()
				console.log(this.webUrl);
			}
		}
	}
</script>

<style>

</style>
